<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript">
(function(){
//****************************************************************************
// API

this.module = function(){
    var args = arguments, ns = args[0], t = typeof ns, expected = 2, obj;
    
    if (t == "object")
        obj = ns;
    else if (t != "string")
        ns = "", expected = 1;

    if(args.length == expected)
        var init, main = args[expected-1];
    else if(args.length == expected+1)
        var init = args[expected-1], main = args[expected];
    else
        return undefined;

    return reuseModule(ns, main) || createModule(ns, init, main);
}

var extend = this.extend = function(l, r)
{
    var api = reuseModule(l, r, true);
    if (api) return api;
    
    var obj = l.prototype || l;
    for (var n in r)
        obj[n] = r[n];
        
    return obj;
};

//****************************************************************************
// Modules

var modules = window.mods = {};

function createModule(ns, init, main){
	var f = init /*&& function(){return f.apply(_, arguments)}*/,
	   API = f || function(){}, n = ns, p = n.split("::"), _;    
    
    if (ns && p.length == 2)
    {
        var inherit = p[0];
        n = p[1];
        if (inherit && inherit != "Object")
            API.prototype = new (findNS(inherit));
    }

    var Scope = main;
    Scope.prototype = new API;
    extend(Scope, {
        module: function(obj){ extend(Scope, obj); },
        extend: function(obj){ extendAPI(Scope, API, obj); }
    });

    var api = ns.indexOf("::") != -1 /*isClass*/ ? API : new API(); 
    var scope = _ = new Scope();

    var id = UID();
    var index = n || "Module_" + id;
    modules[index] = {
        id: id,
        ns: n,
        api: api, 
        API: API,
        scope: scope,
        Scope: Scope
    };    

    if (n) createNS(n, api);
    return api;
}

function findModule(api){
    var m;
    for(var n in modules)
        if ((m = modules[n]).api == api)
            return m;

    return undefined;
}

function reuseModule(ns, main, publish)
{
    var obj = typeof ns == "string" ? findNS(ns) : ns, m = findModule(obj);

    if (!m) return undefined;
    
    if (typeof obj == "function")
    	obj.apply(m.scope);
    else
    	(publish ? m.scope.extend : m.scope.module)(main);

    return m.api;
}

function extendAPI(Scope, API, obj)
{
    var s = Scope.prototype, a = API.prototype, f;
    for (var n in obj)
        a[n] = typeof (f = obj[n]) == "function" ?  bind(f, s) : f;

    return a;
};

function bind(f, _){return function(){return f.apply(_, arguments)}};

function UID(){return ++UID._};
UID._ = -1;

//****************************************************************************
// Namespaces

function createNS(ns, source) {
    if (!ns) return false;
    
    var n = ns.split("."), target = window, o;
    for (var i = 0, l = n.length-1, ni; (ni = n[i]) && (i < l); i++)
        target = (o = target[ni]) ? o : target[ni] = {};
    
    return target[ni] = source || {};
};

function findNS(ns) {
    if (!ns) return false;
    
    var n = ns.split("."), target = window, o;    
    for (var i = 0, ni; ni = n[i]; i++)
        if (o = target[ni])
            target = o
        else
            return undefined;
    
    return target;
};

//****************************************************************************
}).apply(window);
/*
module("MOD", function(){

this.extend({
    show: function(){
        return "I can read " + this.inner() +
            " and " + hidden + " stuff.";
    }
});

var hidden = "hidden";

this.module({
    inner: function(){
        return "protected";
    }
});

});/**/


test = function(main){

    var Module = function(){

    	//f.apply(this, arguments);
    	
    	function bind(f, _){return function(){return f.apply(_, arguments)}};

        var Public = function(){};
        var publicScope = Public.prototype;
        
        var Protected = function(){};
        Protected.prototype = new Public;
        var protectedScope = Protected.prototype;

        publicScope.x = 7;
        publicScope.fn = function(){
            return this.x;
        }
        protectedScope.hidden = "hidden";

        publicScope.fn = bind(publicScope.fn, protectedScope);
        
        return publicScope;
    };    

    return Module;
}


//--------------------------------------------------------------------------
module("String::ns.MyString", function(){
//--------------------------------------------------------------------------

this.config({   
});

this.initialize(function(){
	
});

this.extend({	
});

this.publish({
});

this.protect({
});

//--------------------------------------------------------------------------
});
//--------------------------------------------------------------------------


//--------------------------------------------------------------------------
module({ns: "String::ns.MyString", requires: "ns.util"}}, function(){
//--------------------------------------------------------------------------
    
this.extend({
});


this.protect({
});

//--------------------------------------------------------------------------
});
//--------------------------------------------------------------------------


/*
/**/


</script>
</head>
<body>
</body>
</html>